﻿namespace CNVP.Framework.URLRewriter
{
    using System;
    using System.Web;

    public abstract class BaseModuleRewriter : IHttpModule
    {
        protected BaseModuleRewriter()
        {
        }

        protected virtual void BaseModuleRewriter_AuthorizeRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            //普通页面重定向
            this.Rewrite(app.Request.Path, app);
            //二级域名重定向
            //this.Rewrite(app.Request.Url.AbsoluteUri, app);
        }

        public virtual void Dispose()
        {
        }

        public virtual void Init(HttpApplication app)
        {
            app.AuthorizeRequest += new EventHandler(this.BaseModuleRewriter_AuthorizeRequest);
        }

        protected abstract void Rewrite(string requestedPath, HttpApplication app);
    }
}